package com.tanhua.admin.listener;

import com.tanhua.admin.mapper.LogMapper;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @program: tanhua
 * @description:
 * @author: MR.peng
 * @create: 2022-03-31 15:28
 **/

/*
* 消息监听器
*       1、交给容器管理
*       2、编写方法（自动获取最新消息，并使用：消费）
*               参数类型：消息类型
*       3、方法上配置注解@RabbitListener
*
* */
@Component
public class Loglistener {

    @Autowired
    private LogMapper logMapper;

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(
                            value = "tanhua.log.queue"
                    ),
                    exchange = @Exchange(
                            value = "tanhua.log.exchange",
                            type = ExchangeTypes.TOPIC
                    ),
                    key = "log.*"
            )
    )
    public void log(String message){
        System.out.println("获取到消息"+message);
    }
}
